-
-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic auth support for images #356
Conversation
// If there's no username, skip the authentication | ||
if (request.url.username.isNotEmpty()) { | ||
val basicAuthString = "${request.url.username}:${request.url.password}@" | ||
val url = request.url.toString().replace(basicAuthString, "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this replace have a use, for me it works with and without? I've improved the placeholder handling and added logging for failing requests. Could you have a look at it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cyb3rko should I merge this without your review?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, there's a lot going on at the moment.
Hopefully I can find some time today to take a look.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your changes work on my side.
I could have sworn I found edge cases where it wouldn't work without stripping the URL, but I can't reproduce them at the moment. The only thing that could be interesting is what happens if the response is still 401 even after applying basic auth. Does it always start the interceptor again and again and run into request loops?
With stripping the URL we can not have that problem at all because on the next try it does not have a request.url.username
anymore.
Nevertheless, I'm fine with merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for looking over it. It seems this behavior is required when using okhttp3.Authenticator
Reactive Authentication
Implementations authenticate by returning a follow-up request that includes an authorization
header, or they may decline the challenge by returning null. In this case the unauthenticated
response will be returned to the caller that triggered it.Implementations should check if the initial request already included an attempt to
authenticate. If so it is likely that further attempts will not be useful and the authenticator
should give up.
but the Interceptor doesn't do new requests, so I'll remove it from here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closes #111
I've used an authenticator instead of an interceptor.
The difference is that an interceptor is used on every single call which is not needed in our case.
The authenticator only is called when a request throws a 401 so we try again with basic auth.
Here's my caddy config to test it (username: gotify, password: test)